package com.sgcc.nfc.lock.data.remote.api

import com.sgcc.nfc.lock.core.network.ApiResponse
import com.sgcc.nfc.lock.data.remote.dto.PagedDataDto
import com.sgcc.nfc.lock.data.remote.dto.lock.LockDto
import retrofit2.http.Body
import retrofit2.http.DELETE
import retrofit2.http.GET
import retrofit2.http.POST
import retrofit2.http.PUT
import retrofit2.http.Path
import retrofit2.http.Query

interface LockApi {

    @GET("/api/v1/lock/list")
    suspend fun getLocks(
        @Query("pageNum") pageNum: Int,
        @Query("pageSize") pageSize: Int,
        @Query("roomId") roomId: Long? = null,
        @Query("lockStatus") status: Int? = null,
        @Query("keyword") keyword: String? = null,
        @Query("regionId") regionId: Long? = null
    ): ApiResponse<PagedDataDto<LockDto>>

    @GET("/api/v1/lock/detail/{lockId}")
    suspend fun getLockDetail(
        @Path("lockId") lockId: Long
    ): ApiResponse<LockDto>

    @PUT("/api/v1/lock/{lockId}/status")
    suspend fun updateStatus(
        @Path("lockId") lockId: Long,
        @Body request: UpdateLockStatusRequest
    ): ApiResponse<Unit>

    @POST("/api/v1/lock/nfc/open")
    suspend fun openLock(@Body request: NfcLockRequest): ApiResponse<Unit>

    @POST("/api/v1/lock/nfc/close")
    suspend fun closeLock(@Body request: NfcLockRequest): ApiResponse<Unit>

    @POST("/api/v1/lock/add")
    suspend fun addLock(
        @Query("lockNfcId") lockNfcId: String,
        @Query("roomId") roomId: Long
    ): ApiResponse<Unit>

    @DELETE("/api/v1/lock/delete/{lockId}")
    suspend fun deleteLock(
        @Path("lockId") lockId: Long
    ): ApiResponse<Unit>
}

data class UpdateLockStatusRequest(
    val status: Int,
    val remark: String?
)

data class NfcLockRequest(
    val lockNfcId: String,
    val roomId: Long?,
    val longitude: Double,
    val latitude: Double,
    val remark: String?
)
